package com.webcash.CNBoard.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.webcash.CNBoard.Model.CalendarModel;
import com.webcash.CNBoard.Model.MyProject;
import com.webcash.CNBoard.Model.Work;
import com.webcash.CNBoard.Service.ProjectService;
import com.webcash.CNBoard.util.CalendarUtil;



@Controller
@RequestMapping("/project/calendar")
@SessionAttributes("login" )
public class ProjectCalendarController {
	@Autowired
	MyProject myProject;
	@Autowired
	ProjectService projectService;
	@RequestMapping
	public String action(Model model){
		
		CalendarUtil calendarUtil = new CalendarUtil();
		
		CalendarModel cal = calendarUtil.calendar();
		
		List<Work> workList = projectService.getWorkListByProjectNo(myProject.getProjectNo());
		
		model.addAttribute("calendar", cal);
		model.addAttribute("workList", workList);
		
		return "project/calendar";
	}
	@RequestMapping(value="changeMonth")
	public String changeAction(@RequestParam int year, @RequestParam int month, Model model){
		
		CalendarUtil calendarUtil = new CalendarUtil(year, month);
		CalendarModel cal = calendarUtil.calendar();
		
		List<Work> workList = projectService.getWorkListByProjectNo(myProject.getProjectNo());
		
		model.addAttribute("calendar", cal);
		model.addAttribute("workList", workList);
		
		return "project/calendar";
	}
}
